//
//  NSObject+LXExtension.m
//  绿稀全球购
//
//  Created by 王敏 on 16/7/9.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "NSObject+LXExtension.h"

@implementation NSObject (LXExtension)

+(NSArray*)wmproperties
{
    NSMutableArray *props = [NSMutableArray array];
    
    unsigned int outCount, i;
    
    objc_property_t *properties = class_copyPropertyList([self class],&outCount);
    
    for (i = 0; i<outCount; i++)
        
    {
        objc_property_t property = properties[i];
        const char* char_f =property_getName(property);
        NSString *propertyName = [NSString stringWithUTF8String:char_f];
        [props addObject:propertyName];
    }   
    
    free(properties);   
    
    return props;
}



- (UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
    
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    
    
    if([result isKindOfClass:[UITabBarController class]])
    {
        UITabBarController * tbvc = (UITabBarController*)result;
        UIViewController * vc = tbvc.selectedViewController;
        if([vc isKindOfClass:[UINavigationController class]])
        {
            UINavigationController * nvc = (UINavigationController*)vc;
            UIViewController * vc = nvc.viewControllers.lastObject;
            result = vc;
        }
    }else if ([result isKindOfClass:[UINavigationController class]])
    {
        
        UINavigationController * nvc = (UINavigationController*)result;
        UIViewController * vc = nvc.viewControllers.lastObject;
        result = vc;
    }
    return result;
}



@end
